﻿using System;
using System.Collections;
using System.Collections.Generic;
using LightFactory;

namespace NFactorySample
{
    class Program
    {
        static void Main(string[] args)
        {
            // 'real' instances
            Console.WriteLine("Run 'real' types sample");
            FactoryBase.RegisterFactory(new RealFactory());

            var person = Factory<IPerson>.Create("Real", "Person", 40);
            var company = Factory<ICompany>.Create("Real company");
             
            PrintInfo(company, person);

            // 'test' instances
            Console.WriteLine("\n\nRun 'test' types sample");
            /* 
             * NOTE: if you call FactoryBase.RegisterFactory() multiple times in your application,
             * be aware of old type definitions. 
             */
            FactoryBase.RegisterFactory(new TestFactory()); 

            person = Factory<IPerson>.Create();
            company = Factory<ICompany>.Create();

            PrintInfo(company, person);

#if !THROWABLE
            //try to create an instance of class with default constructor which is not defined in factory...
            var list = Factory<List<int>>.Create();
            //... new instance created  

            if(list != null)
                Console.WriteLine("\n...new instance of List<int> created");
#endif

            //try to create instanse of abstract type which is not defined in factory...
            ICollection thisWillBeNull = Factory<ICollection>.Create();

            //...as a result variable is null
            if (thisWillBeNull == null)
                Console.WriteLine("\n...variable 'thisWillBeNull' is null");

            Console.ReadLine();
        }

        private static void PrintInfo(ICompany company, IPerson person)
        {
            Console.WriteLine("Company: {0}", company.CompanyName);
            Console.WriteLine("Person: \n\t{0}\n\t{1}\n\t{2}", person.FirstName, person.LastName, person.Age);
        }
    }

}
